#include <iostream>
using namespace std;
int cmp(const void *a,const void *b){
    int *a1 = (int *)a;
    int *b1 = (int *)b;
    return *a1-*b1;
}
int main()
{
    int a;
    cin >> a;
    int *arr = new int[a];
    for (int i = 0; i < a; i++)
    {
        cin >> arr[i];
    }
    qsort(arr, a, sizeof(int), cmp);
    for (int i = 0; i < a; i++){
        cout<<arr[i]<<" ";
    }
    cout<<endl;
    for(int i=a-1;i>=0;i--){
        cout<<arr[i]<<" ";
    }
    return 0;
}